﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pgAdmin.aspx.cs" Inherits="EGuayas.Web.Usuario.pgAdmin" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <style>
        /* Styling of global error indicator */
        .form-error-state {
            font-size: 11px;
            padding-left: 20px;
            height: 16px;
            line-height: 18px;
            background: no-repeat 0 0;
            cursor: default;
        }
        .form-error-state-invalid {
            color: #C30;
            background-image: url(../../../../icons/exclamation-png/ext.axd);            
        }
        .form-error-state-valid {
            color: #090;
            background-image: url(../../../../icons/accept-png/ext.axd);
        }

        /* Error details tooltip */
        .errors-tip .error {
            font-style: italic;
        }
    </style>
    <!-- Load Ext JS --> 
    <script src="../Resources/js/Global.js"></script>
    <script src="../Resources/js/Usuario.js"></script>
</head>
<body>
  
    <form id="Form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />   
    <ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
        <Items>
           <%-- Hidden almacena IdPageSession  --%>
           <ext:Hidden Text="" ID="hddIdPageSession" runat="server"></ext:Hidden>
           <%-- Hidden almacena Id Usuario --%>
           <ext:Hidden Text="" ID="hddIdPersonaTmp" runat="server"></ext:Hidden>
          <ext:Hidden Text="" ID="hddShowAlert" runat="server"></ext:Hidden>
           <%-- Hidden delete  
           <ext:Hidden Text="" ID="hddCountNumDoc"  runat="server"></ext:Hidden>
           <ext:Hidden Text="" ID="hddCountNumLoadDoc"  runat="server"></ext:Hidden>
           <ext:Hidden Text="" ID="hddnDocUpRef"  runat="server"></ext:Hidden>   
            --%>
            <ext:FormPanel ID="frmGeneral" runat="server" 
                BodyStyle="background-color: rgb(208, 208, 208);"
                DefaultAnchor="100%"  Layout="AnchorLayout" AutoScroll="true" ButtonAlign="Center"
                Region="Center">                    
                    <Items>
                  <%-- 
                    <ext:TabPanel ID="TabPanel1" 
                    runat="server" 
                    Region="Center"
                    ActiveTabIndex="0"                    
                    MarginSpec="5 5 5 0">
                    <Items>
                        <ext:Hidden Text="" ID="hddnId" runat="server" Name="Id" />
                        <ext:Hidden Text="" ID="hddnIdUser" runat="server" Name="IdUser" />
                        
                   --%> 
                        <ext:Hidden Text="" ID="hddEvento" runat="server"  Name="Evento" />       
                        <ext:UserControlLoader ID="uc_per_U005" UserControlID="wuc_persona" runat="server" Path="~/Usuario/wucPersona.ascx" OnComponentAdded="OnPersonaAdded"/>
                        <ext:UserControlLoader ID="uc_cuenta_U001" UserControlID="wuc_cuenta_u001" runat="server" Path="~/Usuario/wucCuenta.ascx" OnComponentAdded="OnCuentaAdded"/>
                        <ext:FormPanel ID="frmActivo" 
                            runat="server"
                            Frame="true"
                            BodyPadding="5"
                            Collapsible="true"
                            Title="Estado de Usuario"
                            Icon="UserAlert"
                            Layout="AnchorLayout"
                            DefaultAnchor="100%">
                            <Items>
                                <ext:RadioGroup ID="rdgSiNoActivo"  
                                AnchorHorizontal="95%"
                                GroupName="rdgSiNo_group"
                                Name="opc_activar"
                                runat="server"
                                Anchor="none"
                                FieldLabel="Usuario Activo">
                                <LayoutConfig>
                                    <ext:CheckboxGroupLayoutConfig AutoFlex="false" />
                                </LayoutConfig>
                                <Defaults>
                                    <ext:Parameter Name="name" Value="ccType" />
                                    <ext:Parameter Name="style" Value="margin-right:15px;" />
                                </Defaults>
                                <Items>
                                    <ext:Radio ID="rdoSi"
                                        runat="server"
                                        InputValue="S"
                                        BoxLabel="Si" />
                                    <ext:Radio ID="rdoNo"
                                        Checked="true"
                                        runat="server"
                                        InputValue="N"
                                        BoxLabel="No" />                                       
                                </Items>
                                <Listeners>
                                    <Change  Handler="pgFn.ChangeRadioOpc( newValue, oldValue);"></Change>
                                </Listeners>
                            </ext:RadioGroup>
                            </Items>
                            </ext:FormPanel>
                                    
                <%--                   
                   </Items>
                </ext:TabPanel> 
                --%>  
                </Items>
                <DockedItems>
                <ext:Container ID="Container1" 
                    runat="server"
                    Dock="Bottom"
                    PaddingSpec="10 10 10">
                    
                    <LayoutConfig>
                        <ext:HBoxLayoutConfig Align="Middle" />
                    </LayoutConfig>

                    <Items>
                        <ext:Component ID="Component1" 
                            runat="server"
                            ItemID="formErrorState"
                            BaseCls="form-error-state"
                            DefaultAnchor="100%"  
                            Flex="1">
                            <Bin>
                                <ext:XTemplate ID="XTemplate1" runat="server">
                                    <Html>
                                        <ul>
                                            <tpl for=".">
                                                <li>
                                                    <span class="field-name">{name}</span> : <span class="error">{error}</span>
                                                </li>
                                            </tpl>
                                        </ul>
                                    </Html>
                                </ext:XTemplate>
                            </Bin>
                            <ToolTips>
                                <ext:ToolTip ID="ToolTip1"        
                                    runat="server" 
                                    Title="Error Detalles:"
                                    AutoHide="false"
                                    Anchor="top"
                                    MinWidth="450"
                                    MinHeight="80"                                 
                                    MouseOffset="-11,-2"
                                    Closable="true"
                                    Disabled="true"
                                    DefaultAnchor="100%"
                                    ConstrainPosition="true"
                                    Cls="errors-tip" />
                            </ToolTips>
                            
                        </ext:Component>
                        <ext:Button ID="btnSaveForm" 
                            runat="server"      
                            Text="Aceptar"
                            Width="140">                            
                            <DirectEvents>
                                <Click 
                                    OnEvent="SaveClick"
                              
                                    Before="return pgFn.validFormGeneral(this);">
                                   <ExtraParams>
                                       <ext:Parameter Name="prmValues" Value="Ext.encode(App.frmGeneral.getForm().getValues())"   Mode="Raw" />
                                   </ExtraParams>	
                                    <EventMask ShowMask="True"></EventMask>		
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                       
                        <ext:Button ID="btnModificar" 
                            runat="server"      
                            Text="Aceptar"
                            Width="140">                            
                            <DirectEvents>
                                <Click 
                                    OnEvent="ModificarClick"
                                    Before="return pgFn.validFormGeneral(this);">
                                   <ExtraParams>
                                       <ext:Parameter Name="prmValues" Value="Ext.encode(App.frmGeneral.getForm().getValues())"   Mode="Raw" />
                                   
                                    </ExtraParams>	
                                    <EventMask ShowMask="True"></EventMask>		
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button ID="btnEliminar" 
                            runat="server"      
                            Text="Aceptar"
                            Width="140">                            
                            <DirectEvents>
                                <Click 
                                    OnEvent="EliminarClick" >
                                    <ExtraParams>
                                       <ext:Parameter Name="prmValues" Value="Ext.encode(App.frmGeneral.getForm().getValues())"   Mode="Raw" />                                   
                                    </ExtraParams>
                                    <Confirmation ConfirmRequest="true" Title="Confirmar" Message="Desea eliminar usuario?" />
                            		<EventMask ShowMask="True"></EventMask>	
                                </Click>
                               </DirectEvents>
                        </ext:Button>

                    </Items>
                </ext:Container>
                      
            </DockedItems>
            <Buttons>
                
            </Buttons>
        </ext:FormPanel>
       </Items>
    </ext:Viewport>
    </form>
     <ext:XScript ID="XScript1" runat="server">
        <script type="text/javascript">
            var pgFn = new Object();
            pgFn.CountModificar=0;
            pgFn.ChangeRadioOpc  = function (newValue, oldValue) {
                try
                {  
                    var valShowIni = #{hddShowAlert}.getValue(); 
                    if (newValue.rdgSiNo_group=="S" && valShowIni=='true')
                    {
                        Ext.Msg.show({
                            title: '',
                            maxWidth : 300,
                            width: 300,
                            msg:AppLabelGlobalJs.pg_dir_activo,
                            buttons: Ext.Msg.ERROR,
                            animEl: 'elId'
                        });
                    }

                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFn.ChangeRadioOpc: " + jsbug)
                }
            };
            pgFn.ViewGrid= function(msg)
            {
                try
                {

                    window.parent.App.ViewGrid(msg);//Invoca metodo de frame

                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFn.ViewGrid: " + jsbug)
                }
            };            
            pgFn.UpdatePanelReadOnly= function(readOnly)
            {
                try{
                    if (readOnly==true)
                    {
                        fields = #{frmGeneral}.getForm().getFields();
                        fields.each(function (field) {
                            if (field.rendered) {
                                field.el.dom.setAttribute("readOnly",readOnly);
                            }
                            field.setReadOnly(readOnly);
                        });
                    }
                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFn.UpdatePanelReadOnly: " + jsbug)
                }

            };
            pgFn.validFormGeneral= function(me){
                try{

                    var frm  = App.frmGeneral;
                    var done = pgFn.updateErrorState(frm);
                    return (done);  
                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFn.validFormGeneral: " + jsbug)
                }
            };
            pgFn.setValueRadioGroup= function(value_check){
                try
                {
                    #{hddShowAlert}.setValue('false');
                    #{rdgSiNoActivo}.setValue({
                        rdgSiNo_group : value_check
                    });
                    #{hddShowAlert}.setValue('true'); 
                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFn.setValueRadioGroup: " + jsbug)
                }
            };
            pgFn.updateErrorState= function(form,viewTip){
                try{
                    var  errorCmp, errors;
                    
                    errorCmp = form.down('#formErrorState');
                    errors   = AppUser.Global.GetListErrors(form);
                    
                    //Validar Identificacion
                    var errorRuc = AppUser.Global.ValidarDocumento(Ext.getCmp('wuc_persona' + '_' + 'txtIdentifi').getValue());
                    if (errorRuc!="")
                        errors.push({ name: 'Identificación', error: errorRuc});
                   
                    if (typeof viewTip=="undefined")
                        viewTip="S";
                    AppUser.Global.SetErrors(errorCmp, errors,viewTip);                    
                    flag=(errors.length==0);//Agregada la validacion de (+)ruc,cedula
                  
                    form.getForm().isValid();
                    if (flag == false)
                    {
                        var infoAdd = " <ol>";
                        var infodeta = "";
                        /*
                        <ol> 
                             <li>Uno</li> 
                             <li>Dos</li> 
                             <li>Tres</li> 
                        </ol> 
                        */
                        Ext.Array.forEach(errors, function (bug) {
                            infodeta = bug.name+":"+bug.error; 
                            infoAdd += "<li>" + infodeta + "</li>";
                        });
                        infoAdd += "</ol>";

                        Ext.Msg.show({
                            title: '',
                            maxWidth : 300,
                            width: 300,
                            msg:AppLabelGlobalJs.pg_datos_obli + infoAdd,
                            buttons: Ext.Msg.ERROR,
                            animEl: 'elId'
                        });
                    }
                    return(flag);

                }catch(jsbug){
                    AppGlobalJs.showBug("  pgFn.updateErrorState: " + jsbug)
                }
                             
            };
           
           
            pgFn.ShowBtnsRevision= function(n)
            {
                try
                {

                    pgFn.CountModificar=(typeof n !== "undefined")?n:-1;
                    var btnActivar=window.parent.App.btnRevisar;
                    var btnNotificar=window.parent.App.btnNotificar;
                    if (pgFn.CountModificar==-1)
                    {
                        pgFn.CountModificar=0;
                        App.gpDocumentosLoad.getStore().each(function(record){
                            if('S'== record.get('SubirNuevo'))
                                pgFn.CountModificar+=1;
                        });
                    }
                    if (pgFn.CountModificar!=0)
                    {
                        btnActivar.hide();
                        btnNotificar.show();
                    }
                    else
                    {
                        btnActivar.show();
                        btnNotificar.hide();
                    }
                    
                }catch(jsbug){
                    AppGlobalJs.showBug("   pgFn.ShowBtnsRevision: " + jsbug)
                }
            
            };
         
            
       </script>
    </ext:XScript>
</body>
</html>
